Blog

ColdBox Presents: Groovy Integration

Luis Majano April 15, 2009

Spread the word

Luis Majano

April 15, 2009

Spread the word


Share your thoughts

We are releasing a 1.0 version of our GroovyLoader plugin for ColdBox Applications today.  This plugin can be found in the extra downloads section of the ColdBox Website as part of the projects pack.  So what did we do, well, based on Barney Boisvert's inspiration on CFGroovy, we decided to create a plugin that would leverage ColdBox users with the Groovy Scripting Language.  We took some different approaches to the integration and we still have many things planned for it.  But as of now, these are the features that our GroovyLoader exhibits
  • Drop and Play functionality on ANY ColdBox application running on Railo 3.0 >, Adobe CF 8 >, or Open BD
  • Load a groovy environment (1.6.0) into any ColdBox application without modifying the running CF engine.  It uses our integrated JavaLoader to load all necessary libraries without modifying the CF engine.  It can also, load up ANY library you place in the GroovyLoader's lib directory automatically.  So if you kids start fooling around with packaged groovy libraries or java libraries like Hibernate, Spring, Gorm, etc. You can do so, by just dropping the files in that pre-configured folder.
  • Setup of a directory that will hold groovy classes/scripts, that the GroovyLoader will try to load at runtime. Uses the configureClassPath() method of the plugin and usually called once.
  • Integration with the ColdBox cache to provide resolution of parsed groovy-to-java classes for all parsed groovy source, including custom groovy source compilations
  • Ability to clean the parsed class cache from the ColdBox cache
  • Ability to clean the groovy classloader cache of parsed bits
  • Ability to handle complex groovy/java relationships and hierarchies
  • Easily extend/decorate the plugin to meet your needs or enhance it
  • Create groovy classes: create(clazz)
  • Execute groovy scripts: runScript(scriptName,varCollection)
  • Execute groovy source code: runSource(scriptSource,varCollection)
  • Execute groovy source code using a custom tag import
  • Groovy scripts and source code executions will be binded with the following variables. This means that the groovy scripts that are executed using runScript() and runSource() will have the following variables IMPLICITLY created at runtime. This creates a data bridge between ColdFusion and Groovy.
    • A custom passed structure called varCollection. This can have anything you like.
    • The coldbox request collection: coldbox_rc
    • The following coldfusion variables:
      • cf_pagecontext : The coldfusion pagecontext object
      • cf_application : The coldfusion application scope
      • cf_server : The coldfusion server scope
      • cf_session : The coldfusion session scope (if available)
So how does it work. Well, first of all, the download includes a very simple application that you can replicate and learn from.  As our integration progresses we will be adding more functionality and some extra surprises our very own Sana Ullah has been working on for quite a while now. Step1: Install the custom plugin in your application or as a core plugin, basically drop the GroovyLoader folder in your plugins directory of your app Step 2: Init the plugin on application start, usually the application start handler: Step 3: That's it, you can now use it a la carte to create groovy classes, run scripts, or run on deman source code via the method or the imported tag. You can see some sample handler methods below: var rc = event.getCollection(); rc.oHello = instance.GroovyLoader.create("Hello"); event.setView("home"); var rc = event.getCollection(); instance.GroovyLoader.clearClazzCache(); setNextEvent('groovy'); rc.varCollection = {createdAt=now()}; instance.GroovyLoader.runScript('Test',rc.varCollection); event.setView("runscript"); var rc = event.getCollection(); /* Source */ var source = "varCollection.GroovyArray = [1,2,3,4]"; rc.varCollection = {createdAt=now()}; instance.GroovyLoader.runSource(source,rc.varCollection); event.setView("runSource"); def today = coldbox_rc["today"] def SubjectLine = ["Hello","my","name","is","Luis Majano.","Expressed at",today] //Place in ColdBox event context coldbox_rc["SubjectLine"] = SubjectLine.join("_") I hope you enjoy this plugin and you help make it even better and better.

Add Your Comment

(3)

Apr 16, 2009 16:37:35 UTC

by Manithan

That is really great which is the perfect timing i was just looking for it where i have dynamic bean created and was planing to use with spring. i am really excited to try this one. thanks a lot. you rock!!!

Apr 22, 2009 04:45:05 UTC

by Martin

WOW - thats is what i need - thanks a lot! But the only question for me is: How can i use the hibernate plugin? In the CFGroovy project from Barny there is hibernate integrated. Is there a way to integrate it easy in the Coldbox-Groovy Plugin? My idea is to make the whole DAO-Layer in groovy+hibernate. and call it from CFCs :-)

Apr 22, 2009 11:28:51 UTC

by Luis Majano

HI Martin, We will be adding hibernate support in the next release. However, you are more than welcome to give it a shot. All the hooks are in place to set this up.

Recent Entries

Partner with BoxLang and Ortus at Into the Box 2025: Empowering the Future of Modern Software Development!

Partner with BoxLang and Ortus at Into the Box 2025: Empowering the Future of Modern Software Development!

At Ortus Solutions, we’ve always been at the forefront of innovation in the ColdFusion ecosystem. From pioneering modern ColdFusion practices to developing cutting-edge tools and frameworks, we’ve been passionate to help and sup[port the community into shaping the future of web development.That’s why we decided to build BoxLang, our new JVM programming language that not only builds on the strengths of ColdFusion but takes modern software development to the next level.

Maria Jose Herrera
Maria Jose Herrera
December 23, 2024
Why BoxLang When You Have Kotlin, Groovy, Scala, and more…

Why BoxLang When You Have Kotlin, Groovy, Scala, and more…

As we approach a stable release of BoxLang and our continued marketing reaches more folks, many have asked about its purpose. Why create a new language when the JVM ecosystem already includes established languages like Kotlin, Groovy, and Scala, to name a few.

Luis Majano
Luis Majano
December 18, 2024